package dao;

import common.Course;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class GetCourse {
    private static Connection conn=DataBaseConnect.getConn();
    private static String sql="select id,name,teacherId,teacherName,description from course where code=?";
    private static PreparedStatement pstmt;
    static {
        try {
            pstmt=conn.prepareStatement(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public static Course getCourse(String code){
        try {
            pstmt.setString(1,code);
            ResultSet rs=pstmt.executeQuery();
            while (rs.next()){
                return new Course(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5));
            }
            return null;
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("获取我教的课失败");
            return null;
        }
    }
}
